package gin.dev.update;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;

public class DownloadQuere {

	public static ArrayList<DownloadTask> mTaskQuere = new ArrayList<DownloadTask>();
	public static ArrayList<Integer> mProductIDQuere = new ArrayList<Integer>();
	public static ArrayList<String> mPackageNameQuere = new ArrayList<String>();
	
	public static void Add(Context context, DownloadTask task, int productID, String url, String packageName)
	{
		mTaskQuere.add(task);
		mProductIDQuere.add(productID);
		mPackageNameQuere.add(packageName);
		task.execute(url, packageName);
		
		Log.i("test", url);		
		DownloadNotification.Notify(packageName, mTaskQuere.size() - 1, context);
	}
	
	public static void ClearTask(DownloadTask task)
	{
		int id = mTaskQuere.indexOf(task);
		if(id >= 0 && id <mTaskQuere.size())
		{
			mTaskQuere.remove(id);
			mProductIDQuere.remove(id);
			mPackageNameQuere.remove(id);
		}
	}
	
	public static int CheckDownloading(int productID)
	{
		int downloadID = mProductIDQuere.indexOf(productID);
		if(downloadID >= 0)
			return downloadID;
		return -1;
		
	}
	
	public static int CheckDownloading(String packageName)
	{
		int downloadID = mPackageNameQuere.indexOf(packageName);
		if(downloadID >= 0)
			return downloadID;
		return -1;
		
	}
}
